﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Boom.Navigation;

namespace Boom.GameObjects
{
    class ListMonster:DrawableGameComponent
    {
        private List<Monster> _List;
        private List<Texture2D> _ListTextureMonster;
        private int HpLv1, HpLv2;

        //Trả về danh sách các đối tượng quái
        public List<Monster> List
        {
            get { return _List; }
            set { _List = value; }
        }

        public ListMonster(Game Mygame,List<Vector2> PosMonsterLv1,List<Vector2> PosMonsterLv2, ref List<Texture2D> ListTexture)
            : base(Mygame)
        {
            _ListTextureMonster = ListTexture;
            _List = new List<Monster>();
            HpLv1 = Config.DefaultHpMonsterLv1;
            HpLv2 = Config.DefaultHpMonsterLv2;
            Create_List_Monster(PosMonsterLv1, PosMonsterLv2);
        }

        //Tạo danh sách quái vật cấp 1 và cấp 2
        private void Create_List_Monster(List<Vector2> PosLv1, List<Vector2> PosLv2)
        {
            //Tạo quái lv1
            for (int i = 0; i < PosLv1.Count; i++)
            {
                Texture2D TextureLv1 = _ListTextureMonster[0];
                List.Add(new Monster(Game, PosLv1[i], ref TextureLv1, HpLv1, 1, 40, 40));
            }

            //Tạo quái lv2
            for (int j = 0; j < PosLv2.Count; j++)
            {
                Texture2D TextureLv2 = _ListTextureMonster[1];
                List.Add(new Monster(Game, PosLv2[j], ref TextureLv2, HpLv2, 2, 40, 40));
            }
        }

        public override void Initialize()
        {
            for (int i = 0; i < List.Count; i++)
            {
                List[i].Initialize();
            }
            base.Initialize();
        }

        public override void Update(GameTime gameTime)
        {
            for (int i = 0; i < List.Count; i++)
            {
                List[i].Update(gameTime);
                if (!List[i].Enabled)
                {
                    List.RemoveAt(i);
                }
            }
            base.Update(gameTime);
        }

        public override void Draw(GameTime gameTime)
        {
            for (int i = 0; i < List.Count; i++)
            {
                List[i].Draw(gameTime);
            }
            base.Draw(gameTime);
        }
    }
}
